﻿using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Web.UI;
using System.Resources;



namespace wLib.Objects
{
    public static class cWorkerBus
    {


        public static void RegisterFor(eNumComponent forWho, wlibComponent clientTo)
        {
            foreach (cResource res in clientTo.Resources)
            {
                switch (res.Type)
                {
                    case eNumResource.Css:
                        clientTo.Parent.Page.Header.Controls.Add(CreateCssLink(res.Path));
                        break;
                    case eNumResource.JavaScript:
                        IncludeJavaScriptLink(res.Path, clientTo);
                        break;
                }
            }

        }


        public static HtmlLink CreateCssLink(string cssFilePath)
        {
            var link = new HtmlLink();
            link.Attributes.Add("type", "text/css");
            link.Attributes.Add("rel", "stylesheet");
            link.Href = link.ResolveUrl(cssFilePath);
            return link;
        }



        public static void IncludeJavaScriptLink(string jsFilePath, wlibComponent clientTo)
        {
            clientTo.Parent.Page.ClientScript.RegisterClientScriptInclude(
                clientTo.GetType(), jsFilePath, jsFilePath);
        }
        public static void IncludeJavaScriptPortion(string jsPortion, wlibComponent clientTo)
        {
            clientTo.Parent.Page.ClientScript.RegisterStartupScript(
                clientTo.GetType(), "designProperties",jsPortion,true);
        }
        


    }
}
